Exercise 1:
daily_report <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>%
rename(Long = "Long_")
dr <- daily_report %>%
dplyr::group_by(Country_Region) %>%
filter(!is.na(Lat)) %>%
summarize(Cases = sum(Confirmed),
Deaths = sum(Deaths),
Lat = median(Lat),
Long = median(Long))
#Use plotly to troubleshoot median solution
#ggplotly(
#ggplot(dr, aes(x = Long, y = Lat, size = Deaths, text= Country_Region)) +
# borders("world", colour = NA, fill = "grey90") +
# theme_bw() +
# geom_point(shape = 21, color='darkmagenta', fill='darkorchid', alpha = 0.5) +
# labs(title = 'World COVID-19 Confirmed cases',x = '', y = '',
# size="Cases (x10,000)") +
# grey_theme +
# theme(legend.position = "right") +
# coord_fixed(ratio=1.5)
#) # Close plotly
#Correct bad median lat/lons
dr$Lat[dr$Country_Region=="US"] <- 37.0902
dr$Long[dr$Country_Region=="US"] <- -95.7129
dr$Lat[dr$Country_Region=="United Kingdom"] <- 55.3781
dr$Long[dr$Country_Region=="United Kingdom"] <- -3.4360
dr$Lat[dr$Country_Region=="Canada"] <- 56.1304
dr$Long[dr$Country_Region=="Canada"] <- -106.3468
dr$Lat[dr$Country_Region=="Russia"] <- 61.5240
dr$Long[dr$Country_Region=="Russia"] <- 105.3188
dr$Lat[dr$Country_Region=="Denmark"] <- 56.2639
dr$Long[dr$Country_Region=="Denmark"] <- -9.5018
dr$Lat[dr$Country_Region=="Australia"] <- 25.2744
dr$Long[dr$Country_Region=="Australia"] <- 133.7751
#Final plot
ggplot(dr, aes(x = Long, y = Lat, size = Deaths/1000, text= Country_Region)) +
borders("world", colour = NA, fill = "grey90") +
theme_bw() +
geom_point(shape = 21, color='darkmagenta', fill='darkorchid', alpha = 0.5) +
labs(title = 'World COVID-19 Deaths',x = '', y = '',
size="Deaths (x1,000)") +
grey_theme +
theme(legend.position = "right") +
coord_fixed(ratio=1.5)
Exercise 2:
summary(daily_report$Confirmed) #Get summary stats for new case totals
mybreaks <- c(1, 1000, 10000, 100000, 200000) #Set new breaks
ggplot(daily_report, aes(x = Long, y = Lat, size = Confirmed)) +
borders("state", colour = "grey50", fill = "grey90") + #made state borders darker
geom_point(aes(x=Long, y=Lat, size=Confirmed, color=Confirmed),stroke=F, alpha=0.7) +
scale_size_continuous(name="Cases", range=c(1,20), #removed log trans and increased point range
breaks=mybreaks, labels = c("1-999",
"1,000-9,999", "10,000-99,999",
"100,000-199,999", "200,000+")) +
scale_color_viridis_c(option="viridis", name="Cases",
breaks=mybreaks, trans="log", #kept log trans for color scale as it did a better job visually
labels = c("1-999", "1,000-9,999", "10,000-99,999",
"100,000-199,999", "200,000+")) +
#Cleaning up the graph
theme_void() +
guides( color = guide_legend()) +
labs(title = "Modified Anisa Dhana's layout for COVID-19 Confirmed Cases in the US") +
theme(
legend.position = "bottom",
text = element_text(color = "#22211d"),
plot.background = element_rect(fill = "#ffffff", color = NA),
panel.background = element_rect(fill = "#ffffff", color = NA),
legend.background = element_rect(fill = "#ffffff", color = NA)
) +
coord_fixed(ratio=1.5)
Exercise 3: I updated the cases by county color scale
ggplot(data = us, mapping = aes(x = long, y = lat, group = group)) +
coord_fixed(1.3) +
# Add data layer
borders("state", colour = "black") +
geom_polygon(data = state_join, aes(fill = Confirmed)) +
scale_fill_viridis(option = "B", trans = "log10", na.value = "lightgrey",
name = "Confirmed \ncases") +
labs(title = "Number of Confirmed Cases by US County",
x = "Longitude",
y = "Latitude") +
theme_bw()
Exercise 4: I changed the state to Connecticut (home state) and the color scale to the viridis::plasma
daily_report <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>%
rename(Long = "Long_") %>%
filter(Province_State == "Connecticut") %>%
group_by(Admin2) %>%
summarize(Confirmed = sum(Confirmed)) %>%
mutate(Admin2 = tolower(Admin2)) %>%
filter(!Admin2=="unassigned") %>% #remove unassigned cases
rename(Cases = Confirmed) #renaming confirmed cases column for better plotly
us <- map_data("state")
ct_us <- subset(us, region == "connecticut")
counties <- map_data("county")
ct_county <- subset(counties, region == "connecticut")
state_join <- left_join(ct_county, daily_report, by = c("subregion" = "Admin2"))
library(plotly)
ggplotly(
ggplot(data = ct_county, mapping = aes(x = long, y = lat, group = group)) +
coord_fixed(1.3) +
# Add data layer
geom_polygon(data = state_join, aes(fill = Cases), color = "grey40") +
scale_fill_viridis(option = "plasma",
name = "Cases") +
ggtitle("COVID-19 Cases in CT") +
# Cleaning up the graph
labs(x=NULL, y=NULL) +
theme(panel.border = element_blank()) +
theme(panel.background = element_blank()) +
theme(axis.ticks = element_blank()) +
theme(axis.text = element_blank())
)